#include "qbang.h"

QBang::QBang(const QString & filename,QGraphicsScene *scence,qreal angle):QpixmapItem(filename,scence)
{
    this->scence=scence;
    qreal dx,dy;
    qreal rad;
    angle-=7;
    rad=angle*3.14/180;
    dx=150*cos(rad);
    dy=150*sin(rad);
    this->setPos(scence->width()/2+dx,scence->height()-20-dy);
    this->setRotation(90-angle);

}//炮弹出现的位置确定；
void QBang::advance(int phase) {
    if(mapToScene(0,0).x()<0 || mapToScene(0,0).x()>1400 || mapToScene(0,0).y()<0) {
        delete this;
    } else {
        this->setPos(mapToScene(0,-9));//只需y值改变，即可按直线射出；
    }
}//炮弹的刷新；
void QBang::docolliding(){
    score=score+10;
    QNet *net=new QNet("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/net.png",scence);
    net->setPos(mapToScene(0,0));
    delete this;

}//碰撞后炮弹消失；
void  QBang::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget){

    painter->drawPixmap(-pixmap.width()/2,-pixmap.height(),pixmap);
    if(this->collidingItems().count()>0) {

        docolliding();
    }
}//检测碰撞；
